# coding=utf-8


import logging
from project.setting import LOGER_SETTING
import platform
from logging.handlers import RotatingFileHandler as LogHandler

# just for linux
if str(platform.system()) == "Linux":
    from cloghandler import ConcurrentRotatingFileHandler as LogHandler


_log_handler = LogHandler(LOGER_SETTING['file'], "a", LOGER_SETTING['max_size'], LOGER_SETTING['max_count'])
_log_formatter = logging.Formatter(LOGER_SETTING['format'])
_log_handler.setFormatter(_log_formatter)
run_log = logging.getLogger(LOGER_SETTING['name'])


_level = LOGER_SETTING['level']
if _level == "debug":
    run_log.setLevel(logging.DEBUG)
elif _level == "info":
    run_log.setLevel(logging.INFO)
elif _level == "warning":
    run_log.setLevel(logging.WARNING)
elif _level == "error":
    run_log.setLevel(logging.ERROR)
elif _level == "critical":
    run_log.setLevel(logging.CRITICAL)
else:
    run_log.setLevel(logging.NOTSET)


run_log.addHandler(_log_handler)
